package net.aiion.weave.impl.ui.xhtml;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class StyleClass
{
    private final String className;
    private final Map<String, String> classRules;

    public StyleClass(final String aClassName) {
        className = aClassName;
        classRules = new HashMap<>();
    }

    public void addRule(final String aKey, final String aValue) {
        if (!classRules.containsKey(aKey)) {
            classRules.put(aKey, aValue);
        }
    }

    public String getName() {
        return className;
    }

    public Map<String, String> getRules() {
        return Collections.unmodifiableMap(classRules);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + Objects.hashCode(className);
        result = prime * result + Objects.hashCode(classRules);
        return result;
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof StyleClass)) {
            return false;
        }

        final StyleClass other = (StyleClass) obj;
        if (!Objects.equals(className, other.className)) {
            return false;
        }

        if (!Objects.equals(classRules, other.classRules)) {
            return false;
        }
        return true;
    }
}
